const install = (Vue, vm) => {
	const login = () => {
		const token = uni.getStorageSync("storeState");
		// 获取回源页面
		const currentPage = getCurrentPages().pop();
		// 获取页面携带的参数
		const options = currentPage.options;
		// 获取参数的key
		const optionKeys = Object.keys(options);
		// 拼接后的路径
		let params = "";
		if (optionKeys.length !== 0) {
			params = optionKeys.reduce((prev, next) => {
				return prev + next + "=" + options[next] + "&"
			}, "?").slice(0, -1)
		}
		uni.setStorageSync('currentRoute', currentPage.route+params);
		if (!token) {
			setTimeout(() => {
				uni.redirectTo({
					url: "/pages/auth/login/login"
				})
			}, 500)
			return false;
		}
		return true
	}

	vm.$u.utils = {
		login
	};

}

export default {
	install
}
